package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eMessageType;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.player.WorldMessageMgr;

import java.math.BigInteger;

/**
 * 基金
 */
public class FundRecharge extends BaseRecharge {

    public FundRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        return false;
    }

    @Override
    protected void repeatedBuyLogic() {

    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        if(GameConfig.ACTIVITY_PATRONS_FUND == mallInfo.getMallId()){
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.PatronsFund, 1);
            //门客基金世界展示
            WorldMessageMgr.worldNotify(player, eMessageType.BuyPatronsFund.getValue());
        } else if(GameConfig.ACTIVITY_EARNMONEY_FUND == mallInfo.getMallId()){
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.EarnSpeedFund, 1);
            notifyAndLogEarnSpeedFund(player);
        } else if (GameConfig.ACTIVITY_EARNMONEY_PLUS_FUND == mallInfo.getMallId()) {
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.EarnSpeedPlusFound, 1);
            notifyAndLogEarnSpeedPlusFund(player);
        } else if (GameConfig.ACTIVITY_BEAUTY_FUND == mallInfo.getMallId()) {
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.BeautyFund, 1);
            notifyAndLogBeautyFund(player);
        } else if (GameConfig.ACTIVITY_BEAUTY_HIGHER_FUND == mallInfo.getMallId()) {
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.BeautyHigherFund, 1);
            notifyAndLogBeautyHigherFund(player);
        } else if (GameConfig.ACTIVITY_CRICKET_FUND == mallInfo.getMallId()) {
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.CricketFound, 1);
            notifyAndLogCricketFund(player);
        } else if (GameConfig.ACTIVITY_PATRON_LEVEL_FUND == mallInfo.getMallId()){
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.PatronsLevelFund, 1);
            notifyAndLogPatronLevelFund(player);
        }
        player.getModule(CurrencyModule.class).addCurrency(mallInfo.getReward(), eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
        logger.info("订单: {}, 购买 福利商品: {}", orderNo, mallInfo.getMallId());
        return mallInfo.getReward();
    }

    private void notifyAndLogBeautyHigherFund(GamePlayer player) {
        //美女基金世界展示
        WorldMessageMgr.worldNotify(player, eMessageType.BeautyHigherFund.getValue());
        //日志
        BigInteger earnSpeed = player.getUserInfo().getEarnSpeed();
        int titleId = player.getTitleId();
        long vipExp = player.getUserInfo().getVipExp();
        int vipLv = VipMgr.getVipLv(vipExp);
        LogMgr.addLogEarnSpeedFund(player.getUserId(), 5, earnSpeed, titleId, vipExp, vipLv);
    }

    private void notifyAndLogBeautyFund(GamePlayer player) {
        //美女基金世界展示
        WorldMessageMgr.worldNotify(player, eMessageType.BeautyFund.getValue());
        //日志
        BigInteger earnSpeed = player.getUserInfo().getEarnSpeed();
        int titleId = player.getTitleId();
        long vipExp = player.getUserInfo().getVipExp();
        int vipLv = VipMgr.getVipLv(vipExp);
        LogMgr.addLogEarnSpeedFund(player.getUserId(), 4, earnSpeed, titleId, vipExp, vipLv);
    }

    public static void notifyAndLogEarnSpeedFund(GamePlayer player){
        //赚钱基金世界展示
        WorldMessageMgr.worldNotify(player, eMessageType.BuyEarnSpeedFund.getValue());
        //日志
        BigInteger earnSpeed = player.getUserInfo().getEarnSpeed();
        int titleId = player.getTitleId();
        long vipExp = player.getUserInfo().getVipExp();
        int vipLv = VipMgr.getVipLv(vipExp);
        LogMgr.addLogEarnSpeedFund(player.getUserId(), 1, earnSpeed, titleId, vipExp, vipLv);
    }

    public static void notifyAndLogEarnSpeedPlusFund(GamePlayer player) {
        //精进赚钱基金世界展示
//        WorldMessageMgr.worldNotify(player, eMessageType.BuyEarnSpeedPlusFund.getValue());
        //日志
        BigInteger earnSpeed = player.getUserInfo().getEarnSpeed();
        int titleId = player.getTitleId();
        long vipExp = player.getUserInfo().getVipExp();
        int vipLv = VipMgr.getVipLv(vipExp);
        LogMgr.addLogEarnSpeedFund(player.getUserId(), 3, earnSpeed, titleId, vipExp, vipLv);
    }

    private void notifyAndLogCricketFund(GamePlayer player) {
        //促织基金世界展示
        WorldMessageMgr.worldNotify(player, eMessageType.CricketFund.getValue());
        //日志
        BigInteger earnSpeed = player.getUserInfo().getEarnSpeed();
        int titleId = player.getTitleId();
        long vipExp = player.getUserInfo().getVipExp();
        int vipLv = VipMgr.getVipLv(vipExp);
        LogMgr.addLogEarnSpeedFund(player.getUserId(), 6, earnSpeed, titleId, vipExp, vipLv);
    }

    private void notifyAndLogPatronLevelFund(GamePlayer player){
        //门客等级基金世界展示
//        WorldMessageMgr.worldNotify(player, eMessageType.PatronsLevelFund.getValue());
        //日志
        BigInteger earnSpeed = player.getUserInfo().getEarnSpeed();
        int titleId = player.getTitleId();
        long vipExp = player.getUserInfo().getVipExp();
        int vipLv = VipMgr.getVipLv(vipExp);
        LogMgr.addLogEarnSpeedFund(player.getUserId(), 7, earnSpeed, titleId, vipExp, vipLv);
    }
}
